//
// Spring.cs
//
// Copyright (C) 2008 Lukas Lipka <lukaslipka@gmail.com>

using System;
using System.Collections.Generic;

using Cairo;
using Gtk;
//using Gdk;

namespace Dashboard.Latte {

	public class Spring : Gtk.Window {

		private Gdk.Pixbuf pixbuf;

		public event EventHandler Toggled;

		public Spring () : base ("Spring")
		{
			base.AppPaintable = true;
			base.Decorated = false;
			//base.KeepAbove = true;
			base.Gravity = Gdk.Gravity.NorthEast;

			base.SkipPagerHint = true;
			base.SkipTaskbarHint = true;

			base.DefaultWidth = 48;
			base.DefaultHeight = 48;
			//base.Move ();

			Image icon = new Image (Stock.Info, IconSize.Dnd);
			icon.Xalign = 0.8f;
			icon.Yalign = 0.8f;

			/*EventBox eb = new EventBox ();
			eb.Add (icon);*/

			/*EventBox eb = new EventBox ();*/
			Add (icon);

			// Enable translucency if available			
			if (Screen.RgbaColormap != null) {
				base.Colormap = Screen.RgbaColormap;
			}
		}

		protected override bool OnButtonPressEvent (Gdk.EventButton button)
		{
			if (Toggled != null)
				Toggled (this, EventArgs.Empty);
			
			return true;
		}

		protected override bool OnExposeEvent (Gdk.EventExpose evnt)
		{
			if (!IsDrawable)
				return true;

			Cairo.Context gr = Gdk.CairoHelper.Create (evnt.Window);

			gr.Rectangle (evnt.Area.X, evnt.Area.Y, evnt.Area.Width, evnt.Area.Height);
			gr.Color = new Cairo.Color (1.0, 1.0, 1.0, 0.0);
			gr.Operator = Cairo.Operator.Source;
			gr.Paint ();
			
			Cairo.Gradient pat = new Cairo.LinearGradient (0, 0, evnt.Area.Width, evnt.Area.Height);
			pat.AddColorStop (0, CairoFu.GdkColorToCairoColor (new Gdk.Color (0,0,0), 0.1));
			pat.AddColorStop (1, CairoFu.GdkColorToCairoColor (new Gdk.Color (0,97,234), 0.5));

			gr.Pattern = pat;
			gr.Operator = Cairo.Operator.Over;

			gr.Arc (evnt.Area.Width, evnt.Area.Height, evnt.Area.Height, Math.PI, (Math.PI*1.5));
			gr.Fill ();
			
			CairoFu.DisposeContext (gr);
			
			base.OnExposeEvent (evnt);

			return true;
		}
	}
}